/**
 * 
 */
package com.yidin.lsc;

import java.util.List;

import com.yidin.entry.NearByStoreEntry;
import com.yidin.util.NetImageBase;
import com.yidin.util.imageCallback;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 主导航之一我附近的商家
 * 
 * @author cola
 * 
 */
public class NearByStoreAdapter extends MyBaseAdapter {

	public NearByStoreAdapter(List<NearByStoreEntry> info, Context context) {
		super(info, context);
		// TODO Auto-generated constructor stub
		filterArray = info;
		//this.mContext = mContext;
	}

	//private Context mContext;
	private List<NearByStoreEntry> filterArray;

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return filterArray.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return filterArray.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = convertView;
		final int i = position;
		ViewHolder holder = null;
		if (view == null) {
			view = LayoutInflater.from(context).inflate(
					R.layout.nearstoreitem, null);

			holder = new ViewHolder();
			view.setTag(holder);
			holder.tv_catalog = (TextView) view.findViewById(R.id.adress_name);
			holder.tv_nick = (TextView) view.findViewById(R.id.address_content);
			holder.tv_status = (TextView) view.findViewById(R.id.adress_dis);
			holder.icon = (ImageView) view.findViewById(R.id.pro_gameico);
			final ImageView iv = holder.icon;
			Bitmap bm = null;
			if (this.filterArray.get(position).PhotoUrl != null) {// 请求图标
				bm = new NetImageBase().getLogoBitmap(handler, context,
						this.filterArray.get(position).PhotoUrl,
						new imageCallback() {
							public void getImage(Bitmap bm) {
								// TODO Auto-generated method stub
								if (bm != null) {
									iv.setImageBitmap(bm);
									getIsSelected().put(i, bm);
								}
							}
						});

			}
			if (bm != null) {
				iv.setImageBitmap(bm);
				getIsSelected().put(i, bm);
			}
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tv_catalog.setText(filterArray.get(position).AccountName);
		holder.tv_nick.setText(filterArray.get(position).AccountId);
		if (getIsSelected().get(position) != null)
			holder.icon.setImageBitmap(getIsSelected().get(position));
		return view;
	}

	class ViewHolder {

		TextView tv_catalog;
		TextView tv_nick;
		TextView tv_status;
		ImageView icon;
	}
}
